<template>
  <a-card :bordered="false">
    <a-card :bordered="false">
      <detail-list title="基本信息">
        <detail-list-item term="店铺名称">{{ shop.shopName }}</detail-list-item>
        <detail-list-item term="店铺类型">{{ shop.shopTypeName }}</detail-list-item>
        <detail-list-item term="联系人电话">{{ shop.linkmanMobile }}</detail-list-item>
        <detail-list-item term="店铺简介">{{ shop.brief }}</detail-list-item>
        <detail-list-item term="店铺地址">{{ shop.shopAddress }}</detail-list-item>
        <detail-list-item term="详细地址">{{ shop.addressDetail }}</detail-list-item>
      </detail-list>
      <a-divider style="margin-bottom: 32px" />
    </a-card>
    <a-card :bordered="false">
      <detail-list title="高级信息"  :col="2">
        <detail-list-item term="分成类型">
          <a-radio-group v-model="divideType" defaultValue=1  >
            <a-radio-button value="1">按比例分成</a-radio-button>
            <a-radio-button value="2">按次数分成</a-radio-button>
          </a-radio-group>
        </detail-list-item>
        <detail-list-item term="请输入店铺分成比例">
          <a-input v-show="divideType=='1'" placeholder="请输入店铺分成比例" v-model="divideNum" addonAfter="%"  />
          <a-input v-show="divideType=='2'" placeholder="请输入店铺分成比例" v-model="divideNum2" addonAfter="元"  />
        </detail-list-item>
        <detail-list-item term="商品类型">
          <a-select
            style="min-width:200px"
            mode="multiple"
            v-model="selectedGoodType"
            :defaultActiveFirstOption="false"
            :showArrow="false"
            :filterOption="false"
            placeholder="指定商品类型"
            @change="getGoodTypeChange"
            notFoundContent="null"
          >
            <a-select-option :key="n.id" v-for="n in goodTypeList">{{ n.name }}</a-select-option>
          </a-select>
        </detail-list-item>
      </detail-list>
    </a-card>
    <div class="examples">
      <a-button style="margin-left:30px;" size="large" @click="toShopAudit(1)" :disabled="successButton" type="primary"
        >同意</a-button
      >
      <a-button style="margin-left:40px;" size="large" @click="toShopAudit(2)" :disabled="failButton" type="danger"
        >打回</a-button
      >
      <a-modal title="Basic Modal" v-model="modalVisible" @ok="handleModalOk">
      <p>{{modalShowText}}</p>
    </a-modal>
    </div>
  </a-card>
</template>

<script>
import PageLayout from '@/components/page/PageLayout'
import STable from '@/components/table/'
import DetailList from '@/components/tools/DetailList'
import ABadge from 'ant-design-vue/es/badge/Badge'
const DetailListItem = DetailList.Item
import Button from 'ant-design-vue'
import { postAction, getAction } from '@/api/manage'
export default {
  components: {
    Button,
    ABadge,
    DetailList,
    DetailListItem,
    PageLayout,
    STable
  },
  data() {
    return {
      successButton: false,
      failButton: false,
      shop: {},
      shopId: '',
      shopType: '',
      goodTypeList: [],
      selectedGoodType:[],
      divideType:'1',
      divideNum:0,
      modalVisible:false,
      modalShowText:'',
      divideNum2: 0
    }
  },
  filters: {},
  created() {
    this.shopId = this.$route.query.shopId
    this.getGoodTypeList()
  },
  mounted() {},
  activated() {
    this.selectedGoodType=[]
    this.shopId=''
    this.goodTypeList=[]
    this.getShopDetails(this.$route.query.shopId)
    this.successButton = false
    this.failButton = false
    this.getGoodTypeList()
  },
  methods: {
    showGoodType(){
      console.log(this.selectedGoodType)
    },
    handleModalOk(){
      this.modalVisibl=false
    },
    getShopDetails(id) {
      let shopId = { shopId: id }
      this.$nextTick(function() {
        getAction('/shop/web/detail', shopId)
          .then(res => {
            if (res.success) {
              this.shop = res.result
              this.workType=res.result.workType
              this.divideType=res.result.divideType
              this.divideNum=res.result.divideNum
              if (res.result.shopType == 0) {
                return (this.shopType = '百货')
              } else if (res.result.shopType == 1) {
                return (this.shopType = '超市')
              } else {
                return (this.shopType = '五金')
              }
            }
          })
          .catch(err => {})
      })
    },
    getGoodTypeList() {
      getAction('/shopType/getGoodsTypeListOfFirstLevel')
        .then(res => {
          if (res.success) {
            this.goodTypeList = res.result
          }
        })
        .catch(err => {})
    },
    //审核商铺
    toShopAudit(shopStatus) {
      let this_ = this
      if(this.selectedGoodType.length<1 && shopStatus == 1){
        this.$message.warning('请选择商铺可添加的商品种类')
        return
      }
      if(this.divideType==2){
        this.divideNum=this.divideNum2*100
      }
      let obj = { id: this.$route.query.shopId, shopStatus: shopStatus,divideNum:this.divideNum, divideType:this.divideType,goodsTypeList:this.selectedGoodType }
      this.$nextTick(function() {
        postAction('/shop/web/reviewShopInfo', obj)
          .then(res => {
            if (res.success) {
              if (shopStatus == 1) {
                this.successButton = true
                this.$notification.success({
                  message: '审核结果',
                  description: `店铺 : ` + '审核通过'
                })
              } else {
                this.failButton = true
                this.$notification.success({
                  message: '审核结果',
                  description: `店铺 : ` + '驳回审核'
                })
              }
              this.$router.back()
            }
          })
          .catch(err => {})
      })
    },
    getGoodTypeChange(value) {
      this.selectedGoodType=value;
    }
  }
}
</script>

<style lang="scss" scoped>
.examples {
  text-align: center;
}
</style>
